<?php

class Uhet
{
	private $entity;
	
	public function __construct($entity){
		
		$this->entity = $entity;
	}

	/**
	 * @param $resource (entity, view, dao, object, controller, table)
	 * @param $entity (default == null) nome da entidade
	 * @return string com o recurso da entidade
	 * ex: this->getName('view','pessoa');
	 */
	public function getName($resource, $entity = null)
	{
	
		switch($resource){
		
			case 'entity':     $prefix = '';                      break;
			case 'view':       $prefix = VIEW_CLASS_PREFIX;       break;
			case 'dao':        $prefix = DAO_CLASS_PREFIX;        break;
			case 'object':     $prefix = OBJECT_CLASS_PREFIX;     break;
			case 'controller': $prefix = CONTROLLER_CLASS_PREFIX; break;
			case 'table'; break;
		}
		
		if (isset($entity)){
		
			return $prefix . ucfirst($entity);
		} else{
			return $prefix . ucfirst($this->entity);
		} 	
	}

	/**
	 * 
	 * @param $resource
	 * @param $entity
	 * @return unknown_type
	 */
	public function create($resource, $entity = null)
	{
		switch($resource){
			
			case 'view':       $dir = VIEW_DIR;       break;
			case 'dao':        $dir = DAO_DIR;        break;
			case 'controller': $dir = CONTROLLER_DIR; break;
			case 'object':     $dir = OBJECT_DIR;     break;
		}
		
		$name = $this->getName($resource, $entity);
		$file = $dir . $name . '.php';
		
		require_once $file;
		return new $name;
	}
}

?>
